package com.cherry.ssm.user.controller;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.oltu.oauth2.common.exception.OAuthSystemException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.cherry.ssm.user.model.SsoUser;
import com.cherry.ssm.user.service.UserService;


@Controller
public class UserController{
	
	
	@Autowired
	private UserService userService;
	
	/**
	 * 登陆接口
	 * 1、客户端之前验证接入权限的时候获取的客户端本地的ip
	 * 2、判断是否登陆成功
	 * 3、根据登陆账号loginId来判断是否缓存,如果缓存则修改,如果没缓存则添加
	 * 4、重定向到客户端接口或者登陆失败页
	 */
	@RequestMapping(value = "/login")
	public String login(SsoUser users, HttpServletRequest request, HttpServletResponse response, HttpSession session) throws OAuthSystemException{
		return this.userService.login(users, request, response, session);
	}
	
	/**
	 * 通过code获取token
	 * 通过token获取loginId
	 */
	@RequestMapping(value = "/getloginId")
	public HttpEntity getloginId(HttpServletRequest request, HttpSession session){
		return this.userService.getloginId(request, session);
	}
	
//	/**
//	 * 通过token获取loginId
//	 * 登陆拦截里面的
//	 */
//	@RequestMapping(value = "/interceptgetloginId")
//	public HttpEntity interceptgetloginId(HttpServletRequest request, HttpSession session){
//		return this.userService.interceptgetloginId(request, session);
//	}
	
	
	/**
	 * 退出登陆
	 */
	@RequestMapping("/loginout")
	public String loginout(HttpServletRequest request, HttpServletResponse response, HttpSession session){
		return this.userService.loginout(request, response, session);
	}
	  
	
	
	
    
}
